package com.controller;

import com.common.Result;
import com.pojo.entity.Address;
import com.pojo.vo.AddressVo;
import com.service.IAddressService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 杨世博
 * @date: Created in 11:27 2023/6/3
 */
@RestController
@RequestMapping("/address")
@Api(tags = "地址接口")
@Slf4j
public class AddressController {

    @Autowired
    IAddressService addressService;

    /**
     * 获取个人地址
     * @param uid
     * @return
     */
    @GetMapping("/findAddress")
    public Result<List<Address>> findAddress(@RequestParam("uid")Integer uid){
        List<Address> address = addressService.findAddress((long) uid);
        return Result.success(address);
    }

    /**
     * 添加收获地址
     * @param oldAddress
     * @return
     */
    @PutMapping("/addAddress")
    public Result<List<Address>> addAddress(@RequestBody Address oldAddress){
        List<Address> address = addressService.addAddress(oldAddress);
        return Result.success(address);
    }

    /**
     * 修改地址
     * @param oldAddress
     * @return
     */
    @PostMapping("/updateAddress")
    public Result<List<Address>> updateAddress(@RequestBody Address oldAddress){
        List<Address> address = addressService.updateAddress(oldAddress);
        return Result.success(address);
    }

    @DeleteMapping("/deleteAddress")
    public Result<List<Address>> deleteAddress(@RequestParam("uid")Integer uid, @RequestParam("addressId")Integer addressId){
        List<Address> address = addressService.deleteAddress((long) uid,addressId);
        return Result.success(address);
    }
}
